package com.weijianhuawen.wjblog.admin.controller;

import com.weijianhuawen.wjblog.admin.mode.vo.user.*;
import com.weijianhuawen.wjblog.admin.service.AdminUserService;
import com.weijianhuawen.wjblog.common.aspect.ApiOperationLog;
import com.weijianhuawen.wjblog.common.utils.PageResponse;
import com.weijianhuawen.wjblog.common.utils.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @version: java version 8
 * @Author: weijianhuawen
 * @description:
 * @date: 2024-10-19 13:07
 */
@RequestMapping("/admin")
@Api(tags = "Admin 用户模块")
@RestController
public class AdminUserController {
    @Resource
    private AdminUserService adminUserService;

    @PostMapping("/password/update")
    @ApiOperation(value = "修改用户密码")
    @ApiOperationLog(description = "修改密码")
    public Object updatePassword(@RequestBody @Validated UpdateAdminUserPasswordReqVo vo) {
        Response<Object> response = adminUserService.updateAdminUserPassword(vo);
        System.out.println(response);
        return response;
    }

    @GetMapping("/user/info")
    @ApiOperation(value = "获取用户名")
    @ApiOperationLog(description = "获取用户名")
    public Object findUserInfo() {
        return adminUserService.findUserInfo();
    }

    // 获取用户基本信息，用户名，用户id，昵称，头像
    @GetMapping("user/base")
    @ApiOperation(value = "获取登录用户基本信息")
    @ApiOperationLog(description = "获取登录用户基本信息")
    public Response findUserBaseInfo() {
        return adminUserService.findUserBaseInfo();
    }

    // 获取用户详细信息
    @GetMapping("/user/detail")
    @ApiOperation(value = "获取用户详细信息")
    @ApiOperationLog(description = "获取用户详细信息")
    public Response findUserDetailInformation() {
        return adminUserService.findUserDetailInformation();
    }

    // 更新用户详细信息
    @PostMapping("/detail/update")
    @ApiOperation(value = "更新用户详细信息")
    @ApiOperationLog(description = "更新用户详细信息")
    public Response updateUserDetailInformation(@RequestBody @Validated UpdateUserDetailInformationReqVo vo) {
        return adminUserService.updateUserDetailInformation(vo);
    }

    // 更新用户个人资料
    @PostMapping("/person/update")
    @ApiOperation(value = "个人资料修改")
    @ApiOperationLog(description = "修改个人资料")
    public Response updateUserPersonInfo(@RequestBody @Validated UpdateUserPersonInformationReqVo vo) {
        return adminUserService.updateUserPersonInformation(vo);
    }

    // 获取用户账号信息
    @GetMapping("/user/count")
    @ApiOperation(value = "获取用户账户信息")
    @ApiOperationLog(description = "获取用户账户信息")
    public Response findUserCountInfo() {
        return adminUserService.findUserCountInfo();
    }

    // 修改账户手机号
    @PostMapping("/user/phone/update")
    @ApiOperation(value = "修改手机号")
    @ApiOperationLog(description = "修改手机号")
    public Response updateUserCountPhone(@RequestBody @Validated UpdateCountPhoneReqVo vo) {
        return adminUserService.updateCountPhone(vo);
    }

    // 修改qq号
    @PostMapping("/user/qq/update")
    @ApiOperation(value = "修改qq号")
    @ApiOperationLog(description = "修改qq号")
    public Response updateUserCountQq(@RequestBody @Validated UpdateCountQqReqVo vo) {
        return adminUserService.updateCountQq(vo);
    }

    // 修改邮箱
    @PostMapping("/user/mail/update")
    @ApiOperation(value = "修改邮箱")
    @ApiOperationLog(description = "修改邮箱")
    public Response updateUserCountMail(@RequestBody @Validated UpdateCountMailReqVo vo) {
        return adminUserService.updateCountMail(vo);
    }

    // 解绑qq号
    @PostMapping("/qq/unbind")
    @ApiOperation(value = "解绑qq号")
    @ApiOperationLog(description = "将用户qq号解除绑定")
    public Response unbindUserQq(@RequestBody @Validated UnbindUserCountQqReqVo vo) {
        return adminUserService.unbindUserQq(vo);
    }

    // 解绑手机号
    @PostMapping("/phone/unbind")
    @ApiOperation(value = "解绑手机号")
    @ApiOperationLog(description = "解绑用户手机号")
    public Response unbindUserPhone(@RequestBody @Validated UnbindUserCountPhoneReqVo vo) {
        return adminUserService.unbindUserPhone(vo);
    }

    // 获取用户信息分页列表
    @PostMapping("/user/page/list")
    @ApiOperation(value = "获取用户信息分页列表")
    @ApiOperationLog(description = "获取用户详细信息分页列表")
    public PageResponse findUserDetailPageList(@RequestBody @Validated FindUserDetailPageListReqVo vo) {
        return adminUserService.findUserDetailPageList(vo);
    }

    // 更新用户资料信息
    @PostMapping("/message/update")
    @ApiOperation(value = "更新用户资料信息")
    @ApiOperationLog(description = "更新用户资料信息")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Response updateUserMessage(@RequestBody @Validated UpdateUserMessageReqVo vo) {
        return adminUserService.updateUserMessage(vo);
    }

    // 更新用户账号信息
    @PostMapping("/account/update")
    @ApiOperation(value = "更新用户账号信息")
    @ApiOperationLog(description = "更新用户密码，手机号，邮箱，qq等账号信息")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Response updateUserAccount(@RequestBody @Validated UpdateUserAccountReqVo vo) {
        return adminUserService.updateUserAccount(vo);
    }

    // 修改用户状态
    @PostMapping("/update/account/status")
    @ApiOperation(value = "修改用户账号状态")
    @ApiOperationLog(description = "修改用户账号状态")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Response updateAccountStatus(@RequestBody @Validated UpdateUserStatusReqVo vo) {
        return adminUserService.updateUserStatus(vo);
    }

    // 注销用户
    @PostMapping("/cancel/account")
    @ApiOperation(value = "注销用户（逻辑）")
    @ApiOperationLog(description = "逻辑删除用户数据")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Response cancelUserAccount(@RequestBody @Validated DeleteUserAccountReqVo vo) {
        return adminUserService.cancelUserAccount(vo);
    }
    // 恢复用户
    @PostMapping("/recovery/account")
    @ApiOperation(value = "恢复用户（逻辑）")
    @ApiOperationLog(description = "恢复逻辑删除的用户数据")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Response recoveryUserAccount(@RequestBody @Validated RecoverUserAccountReqVo vo) {
        return adminUserService.recoverUserAccount(vo);
    }

}
